<?php require_once('Connections/dodol.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_dodol, $dodol);
$query_matkul = "SELECT kode_matkul FROM matkul ORDER BY kode_matkul ASC";
$matkul = mysql_query($query_matkul, $dodol) or die(mysql_error());
$row_matkul = mysql_fetch_assoc($matkul);
$totalRows_matkul = mysql_num_rows($matkul);

$colname1_matkul_db = "-1";
if (isset($_POST['kd'])) {
  $colname1_matkul_db = $_POST['kd'];
}
$colname2_matkul_db = "-1";
if (isset($_POST['ta'])) {
  $colname2_matkul_db = $_POST['ta'];
}
mysql_select_db($database_dodol, $dodol);
$query_matkul_db = sprintf("SELECT nim, ta, sem FROM matkul_db WHERE kode_matkul = %s AND ta = %s", GetSQLValueString($colname1_matkul_db, "text"),GetSQLValueString($colname2_matkul_db, "text"));
$matkul_db = mysql_query($query_matkul_db, $dodol) or die(mysql_error());
$row_matkul_db = mysql_fetch_assoc($matkul_db);
$totalRows_matkul_db = mysql_num_rows($matkul_db);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="">
  Kode Matkul
    <select name="kd" id="kd">
      <option value="">...</option>
      <?php
do {  
?>
      <option value="<?php echo $row_matkul['kode_matkul']?>"><?php echo $row_matkul['kode_matkul']?></option>
      <?php
} while ($row_matkul = mysql_fetch_assoc($matkul));
  $rows = mysql_num_rows($matkul);
  if($rows > 0) {
      mysql_data_seek($matkul, 0);
	  $row_matkul = mysql_fetch_assoc($matkul);
  }
?>
    </select> 
    <label for="ta">Tahun Ajaran</label>
    <select name="ta" id="ta">
      <option selected value="">...</option>
      <option value="2009/2010">2009/2010</option>
      <option value="2010/2011">2010/2011</option>
      <option value="2011/2012">2011/2012</option>
    </select>
    <br>
    <input type="submit" name="button" id="button" value="Show">
    <br>
  Show Data; Kode Matkul: <?php echo $_POST['kd'];?> Tahun Ajaran: <?php echo $_POST['ta'];?> TOTAL: <?php echo $totalRows_matkul_db ?><br>
  <table border="1">
    <tr>
      <td>nim</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_matkul_db['nim']; ?></td>
      </tr>
      <?php } while ($row_matkul_db = mysql_fetch_assoc($matkul_db)); ?>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($matkul);

mysql_free_result($matkul_db);
?>
